package cn.edu.xust.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.xust.util.PageUtils;
import cn.edu.xust.util.Query;

import cn.edu.xust.dao.GatewayDao;
import cn.edu.xust.entity.GatewayEntity;
import cn.edu.xust.service.GatewayService;


@Service("gatewayService")
public class GatewayServiceImpl extends ServiceImpl<GatewayDao, GatewayEntity> implements GatewayService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GatewayEntity> page = this.page(
                new Query<GatewayEntity>().getPage(params),
                new QueryWrapper<GatewayEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public GatewayEntity getByName(String name) {
        QueryWrapper<GatewayEntity> wap = new QueryWrapper<GatewayEntity>().eq("name", name);
        return baseMapper.selectOne(wap);
    }

    @Override
    public GatewayEntity getByIP(String ip) {
        QueryWrapper<GatewayEntity> wap = new QueryWrapper<GatewayEntity>().eq("ip", ip);
        return baseMapper.selectOne(wap);
    }

    @Override
    public List<GatewayEntity> getByHotel(String hotelid) {
        QueryWrapper<GatewayEntity> wap = new QueryWrapper<GatewayEntity>().eq("hotelid", hotelid).orderByAsc("note");
        return baseMapper.selectList(wap);
    }

}

